<template>
  <div class="search-bar">
    <el-form :inline="true" :model="formItem" class="form-filter" size="mini">
      {{range $i, $v := .Fields}}<el-form-item label="{{$v.TableFieldComment}}" prop="text">
         <el-input v-model="formItem.text" placeholder="请输入{{$v.TableFieldComment}}" />
        </el-form-item>
      {{end}}
      <el-form-item>
        <el-button plain icon="el-icon-search" @click="search" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { list } from '@neu/dcam-ui/api/{{.LowerClassName}}'

// 定义一个查询表单原始项
const formItem = {
 {{range $i, $v := .Fields}} e_{{$v.FieldName}}:'',
 {{end}}
}

export default {
  name: '{{.ClassName}}TableFilter',
  data() {
    return {
      formItem: {
        ...formItem
      },
      inputDisabled: true,
      select: '',
      placeholder: ''
    }
  },
  mounted() {
  },
  methods: {
    // 查询按钮点击事件处理
    search: function() {
      this.$parent.filter(this.formItem)
    },
    // 重置按钮点击事件处理
    reset: function() {
      this.formItem = {
        ...formItem
      }
      this.search()
    },
    // 复合型输入框 input 值改变事件
    onMixedInputChange(value) {
      if (value === '') {
        this.search()
      }
    },
    // 复合型输入框 select 值改变事件
    onMixedSelectChange(value) {
      this.options.find((option) => {
        if (option.value === value) {
          this.placeholder = '请输入' + option.label
        }
        this.formItem[option.value] = ''
      })
      this.inputDisabled = false
      // 清空时，触发查询
      if (value === '') {
        this.search()
        this.inputDisabled = true
        this.placeholder = ''
      }
    },
    onTypeChange(value) {
      this.search()
    }
  }
}
</script>
